-------------------------------------------------------------------------------
--
--  Mod Name : BlinkQuestHelper v2.3
--  Author   : Blink
--  Date     : 2005/03/28
--  LastUpdate : 2010/10/16
--
-------------------------------------------------------------------------------

local frame
local dropdown
local questLineIndex = 1
local BQH_WATCHFRAME_LINKBUTTONS = {}
local BQH_WATCHFRAME_SETLINES = {}
local BQH_WATCHFRAME_SETLINES_NUMLINES;
local ori_GetQuestLogTitle
local GameTooltip = _G.GameTooltip

local DASH_NONE = 0;
local DASH_SHOW = 1;
local DASH_HIDE = 2;
local DASH_WIDTH;
local IS_HEADER = true;

local tomtomBox = {}
local completeCheckBox = {}

local function playSoundFor(soundPath)
	if soundPath and soundPath~="" then
		if ((string.sub(soundPath, -4) == ".wav") or (string.sub(soundPath, -4) == ".mp3") or (string.sub(soundPath, -4) == ".ogg")) then
			PlaySoundFile(soundPath)
		else
			PlaySound(soundPath)
		end
	end
end
local Complete_Sound = {
	{ text = "없음", value = "", func = function (self) end,	},
	{ text = "PVPENTERQUEUE", value = "PVPENTERQUEUE", func = function (self) playSoundFor(self.value) end,	},
	{ text = "PVPTHROUGHQUEUE", value = "PVPTHROUGHQUEUE", func = function (self) playSoundFor(self.value) end, },
	{ text = "GLUECREATECHARACTERBUTTON", value = "GLUECREATECHARACTERBUTTON", func = function (self) playSoundFor(self.value) end, },
	{ text = "GLUEENTERWORLDBUTTON", value = "GLUEENTERWORLDBUTTON", func = function (self) playSoundFor(self.value) end, },
	{ text = "QUESTCOMPLETED", value = "QUESTCOMPLETED", func = function (self) playSoundFor(self.value) end, },
	{ text = "INTERFACESOUND_MONEYFRAMEOPEN", value = "INTERFACESOUND_MONEYFRAMEOPEN", func = function (self) playSoundFor(self.value) end, },
	{ text = "igPlayerInvite", value = "igPlayerInvite", func = function (self) playSoundFor(self.value) end, },
	{ text = "LEVELUP", value = "LEVELUP", func = function (self) playSoundFor(self.value) end, },
	{ text = "QUESTADDED", value = "QUESTADDED", func = function (self) playSoundFor(self.value) end, },
	{ text = "gsCharacterCreationCreateChar", value = "gsCharacterCreationCreateChar", func = function (self) playSoundFor(self.value) end, },
	{ text = "TalentScreenOpen", value = "TalentScreenOpen", func = function (self) playSoundFor(self.value) end, },
	{ text = "ReadyCheck", value = "ReadyCheck", func = function (self) playSoundFor(self.value) end, },
	{ text = "RaidWarning", value = "RaidWarning", func = function (self) playSoundFor(self.value) end, },
	{ text = "AuctionWindowOpen", value = "AuctionWindowOpen", func = function (self) playSoundFor(self.value) end, },
	{ text = "AuctionWindowClose", value = "AuctionWindowClose", func = function (self) playSoundFor(self.value) end, },
	{ text = "PeonBuildingComplete1", value = "Sound\\Creature\\Peon\\PeonBuildingComplete1.wav", func = function (self) playSoundFor(self.value) end, },
	{ text = "PeonReady1", value = "Sound\\Creature\\Peon\\PeonReady1.wav", func = function (self) playSoundFor(self.value) end, },
	{ text = "PeasantReady1", value = "Sound\\Creature\\Peasant\\PeasantReady1.wav", func = function (self) playSoundFor(self.value) end, },
	{ text = "igPlayerBind", value = "Sound\\Interface\\igPlayerBind.wav", func = function (self) playSoundFor(self.value) end, },
	{ text = "TEMPEST_Millhouse_Ready01", value = "Sound\\Creature\\MillhouseManastorm\\TEMPEST_Millhouse_Ready01.wav", func = function (self) playSoundFor(self.value) end, },
	{ text = "TEMPEST_Millhouse_Slay01", value = "Sound\\Creature\\MillhouseManastorm\\TEMPEST_Millhouse_Slay01.wav", func = function (self) playSoundFor(self.value) end, },
	{ text = "CowDeath", value = "Sound\\Creature\\Cow\\CowDeath.wav", func = function (self) playSoundFor(self.value) end, },
	{ text = "HumanExploration", value = "Sound\\interface\\HumanExploration.wav", func = function (self) playSoundFor(self.value) end, },
	{ text = "뿅~", value = "Sound/Spells/Bonk1.ogg", func = function (self) playSoundFor(self.value) end, },
}

local function print(msg)
	if(ChatFrame1) then
		ChatFrame1:AddMessage(msg, 1.0, 1.0, 0.0)
	end
end

local function load(self)

	SLASH_BQH1 = "/questhelper"
	SLASH_BQH2 = "/qh"
	SLASH_BQH3 = "/퀘도우미"
	SlashCmdList["BQH"] = function (msg) BlinkQuestHelper_SlashCmd(msg) end

	self:RegisterEvent("UI_INFO_MESSAGE")
	self:RegisterEvent("QUEST_WATCH_UPDATE")
	self:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
	self:RegisterEvent("QUEST_LOG_UPDATE")
	self:RegisterEvent("UPDATE_FACTION")
	self:RegisterEvent("UNIT_QUEST_LOG_CHANGED")
	self:SetScript("OnEvent", BlinkQuestHelper_OnEvent)

	dropdown = CreateFrame("FRAME", "BlinkQuestHelperDropDown", QuestLogFrame, "UIDropDownMenuTemplate")

	BlinkQuestHelper_Init()
	BlinkQuestHelper_ToggleQuestLevel(BQH_CONFIG.QuestLevel)
	BlinkQuestHelper_ToggleQuestWatch(BQH_CONFIG.QuestWatch)
	BlinkQuestHelper_Status()
	BQH_BlinkGUIRegister()

	_G.MAX_QUEST_WATCH_TIME = nil

	DASH_WIDTH = WatchFrame.lineCache:GetFrame().dash:GetWidth()

	WatchFrame_RemoveObjectiveHandler(WatchFrame_DisplayTrackedQuests)
end

-- from QuestHelper
local function clamp(v)
	if v < 0 then return 0 elseif v > 1.0 then return 1.0 else return v end
end
local function colorlerp(position, r1, g1, b1, r2, g2, b2)
	local antip = 1 - position
	local color = {}
	color.r = clamp(r1 * antip + r2 * position)
	color.g = clamp(g1 * antip + g2 * position)
	color.b = clamp(b1 * antip + b2 * position)
	return color
end

-- We're just gonna do the same thing QH originally did - red->yellow->green.
local function difficulty_color(position)
  if position < 0 then position = 0 end
  if position > 1 then position = 1 end
  return (position < 0.5) and colorlerp(position * 2, 1, 0, 0, 1, 1, 0) or colorlerp(position * 2 - 1, 1, 1, 0, 0, 1, 0)
end

local function _QuestLog_HighlightQuest(questLogTitle)
	local prevParent = QuestLogHighlightFrame:GetParent();
	if ( prevParent and prevParent ~= questLogTitle ) then
		-- set prev quest's colors back to normal
		local prevName = prevParent:GetName();
		prevParent:UnlockHighlight();
		prevParent.tag:SetTextColor(prevParent.r, prevParent.g, prevParent.b);
		prevParent.groupMates:SetTextColor(prevParent.r, prevParent.g, prevParent.b);
	end
	if ( questLogTitle ) then
		local name = questLogTitle:GetName();
		-- highlight the quest's colors
		questLogTitle.tag:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
		questLogTitle.groupMates:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
		questLogTitle:LockHighlight();
		-- reposition highlight frames
		QuestLogHighlightFrame:SetParent(questLogTitle);
		QuestLogHighlightFrame:SetPoint("TOPLEFT", questLogTitle, "TOPLEFT", 0, 0);
		QuestLogHighlightFrame:SetPoint("BOTTOMRIGHT", questLogTitle, "BOTTOMRIGHT", 0, 0);
		QuestLogSkillHighlight:SetVertexColor(questLogTitle.r, questLogTitle.g, questLogTitle.b);
		QuestLogHighlightFrame:Show();
	else
		QuestLogHighlightFrame:Hide();
	end
end

local function _QuestLog_ToggleQuestWatch(questIndex)
	if ( IsQuestWatched(questIndex) ) then
		RemoveQuestWatch(questIndex);
		WatchFrame_Update();
	else
		if ( GetNumQuestWatches() >= MAX_WATCHABLE_QUESTS ) then -- Check this first though it's less likely, otherwise they could make the frame bigger and be disappointed
			UIErrorsFrame:AddMessage(format(QUEST_WATCH_TOO_MANY, MAX_WATCHABLE_QUESTS), 1.0, 0.1, 0.1, 1.0);
			return;
		end
		AddQuestWatch(questIndex);
		WatchFrame_Update();
	end
end

local function getQuestLogIndexByQuestId(questId)
	local numEntries = GetNumQuestLogEntries()
	local qid
	for i=1, numEntries, 1 do
		_, _, _, _, _, _, _, _, qid = GetQuestLogTitle(i)
		if qid == questId then
			return i
		end
	end
end

local function setTootipQuestProgress(tt)
	local t, color
	local fmt = "%.2x"
	if tt then
		for i=1, 30 do
			t = _G[tt:GetName() .. "TextLeft"..i]
			if not t or not t:GetText() then
				break
			end
			color = bqh_GetLeaderboardColor(t:GetText())
			if color then
				t:SetText("|c"
					..string.format(fmt, 255)
					..string.format(fmt, color.r*255 )
					..string.format(fmt, color.g*255 )
					..string.format(fmt, color.b*255 )
					..t:GetText() .. "|r")
			end
		end
	end
end


--[[
block 문제로 사용안함
local function colorizeQuestText(text)
	-- from nQuestLog
	text = gsub(text,"([^%a%d%|])(%d+)([^%a%d%|])", "%1|cffffffff%2|r%3") -- Match numbers
	text = gsub(text,"([^%a%d%|])(%d+)([^%a%d%|])", "%1|cffffffff%2|r%3") -- Match numbers again

	text = gsub(text,"("..UnitName("player")..")", "|cffffffff%1|r")
	text = gsub(text,"([^%s%|r]+)에게 ", "|cffffffff%1|r에게 ")
	text = gsub(text,"([^%s%|r]+)(%|1으로;로;) ", "|cffffffff%1|r%2 ")
	text = gsub(text,"([^%s%|r]+)(%|1을;를;) ", "|cffffffff%1|r%2 ")
	text = gsub(text,"([^%s%|r]+)(%|1이여;여;) ", "|cffffffff%1|r%2 ")
	text = gsub(text,"([^%s%|r]+)(%|1이;가;) ", "|cffffffff%1|r%2 ")
	text = gsub(text,"([^%s%|r]+)(%|1과;와;) ", "|cffffffff%1|r%2 ")
	text = gsub(text,"([^%s%|r]+)(%|1이라는;라는;) ", "|cffffffff%1|r%2 ")
	text = gsub(text,"([^%s%|r]+)(%|1은;는;) ", "|cffffffff%1|r%2 ")

	text = gsub(text,"(북서쪽)([^%a%d])", "|cffffffff%1|r%2")
	text = gsub(text,"(북동쪽)([^%a%d])", "|cffffffff%1|r%2")
	text = gsub(text,"(남서쪽)([^%a%d])", "|cffffffff%1|r%2")
	text = gsub(text,"(남동쪽)([^%a%d])", "|cffffffff%1|r%2")
	text = gsub(text,"(북서쪽)([^%a%d])", "|cffffffff%1|r%2")
	text = gsub(text,"(북쪽)([^%a%d])", "|cffffffff%1|r%2")
	text = gsub(text,"(서쪽)([^%a%d])", "|cffffffff%1|r%2")
	text = gsub(text,"(동쪽)([^%a%d])", "|cffffffff%1|r%2")
	text = gsub(text,"(남쪽)([^%a%d])", "|cffffffff%1|r%2")
	return text
end
]]

local bqh_watchButtonIndex = 1;
local function bqh_GetLinkButton ()
	local button = BQH_WATCHFRAME_LINKBUTTONS[bqh_watchButtonIndex]
	if ( not button ) then
		BQH_WATCHFRAME_LINKBUTTONS[bqh_watchButtonIndex] = WatchFrame.buttonCache:GetFrame();
		button = BQH_WATCHFRAME_LINKBUTTONS[bqh_watchButtonIndex]
	end
	bqh_watchButtonIndex = bqh_watchButtonIndex + 1
	return button
end

local function bqh_ResetLinkButtons ()
	bqh_watchButtonIndex = 1
end

local function bqh_ReleaseUnusedLinkButtons ()
	local watchButton
	for i = bqh_watchButtonIndex, #BQH_WATCHFRAME_LINKBUTTONS do
		watchButton = BQH_WATCHFRAME_LINKBUTTONS[i]
		watchButton.type = nil
		watchButton.index = nil
		watchButton:Hide()
		watchButton.frameCache:ReleaseFrame(watchButton)
		BQH_WATCHFRAME_LINKBUTTONS[i] = nil
	end
end

local function bqh_GetQuestLine ()
	local line = WATCHFRAME_QUESTLINES[questLineIndex]
	if ( not line ) then
		WATCHFRAME_QUESTLINES[questLineIndex] = WatchFrame.lineCache:GetFrame()
		line = WATCHFRAME_QUESTLINES[questLineIndex]
	end

	line:Reset()
	questLineIndex = questLineIndex + 1
	return line
end

local function bqh_ResetQuestLines ()
	questLineIndex = 1
end

local function bqh_ReleaseUnusedQuestLines ()
	local line
	for i = questLineIndex, #WATCHFRAME_QUESTLINES do
		line = WATCHFRAME_QUESTLINES[i]
		line:Hide()
		line.frameCache:ReleaseFrame(line)
		WATCHFRAME_QUESTLINES[i] = nil
	end
end

local function bqh_buildQuestLevelTag(questLogTitleText, level, questTag, suggestedGroup, isDaily, hideDaily)
	local tag = ""

	if questLogTitleText then
		if questTag == ELITE then
			tag = "["..level.."+"
		elseif questTag == GROUP then
			tag = "["..level.."+"
			if suggestedGroup>0 then
				tag = tag .. suggestedGroup
			end
		elseif questTag == LFG_TYPE_DUNGEON then
			tag = "["..level.."D"
		elseif questTag == RAID then
			tag = "["..level.."R"
		elseif questTag == "전쟁" then -- ? PVP?
			tag = "["..level.."W"
		elseif questTag then
			tag = "["..level..questTag
		else
			tag = "["..level
		end
		if isDaily and not hideDaily then
			tag = tag .. ":" .. DAILY
		end
		tag = tag .. "]"
	end
	return tag
end

function bqh_GetQuestLogTitle(questLogID)
	local questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID, startEvent, displayQuestID = ori_GetQuestLogTitle(questLogID)
	if not isHeader and questTitle and ( BQH_CONFIG.QuestLevel == 1 or ENABLE_COLORBLIND_MODE == "1" ) then
		local levelTag = bqh_buildQuestLevelTag(questTitle, level, questTag, suggestedGroup, isDaily, true)
		questTitle = levelTag .. " " .. questTitle
	end
	return questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID, startEvent, displayQuestID
end

function bhq_ToggleWayPoint(questId)

	local _, posX, posY, objective = QuestPOIGetIconInfo(questId)
	local numEntries, numQuests = GetNumQuestLogEntries();
	local qtitle, title, level, qid, questIndex, color
	local c, z = GetCurrentMapContinent(), GetCurrentMapZone()
	if ( posX and posY and TomTom) then
		questIndex = 1
		title, level, _, _, _, _, _, _, qid = GetQuestLogTitle(questIndex)
		while qid do
			if questId == qid then
				qtitle = title
				break
			end
			questIndex = questIndex + 1
			title, level, _, _, _, _, _, _, qid = GetQuestLogTitle(questIndex)
		end
		color = bqh_GetQuestDifficultyColor(level)
		if tomtomBox[questId] then
			TomTom:RemoveWaypoint(tomtomBox[questId])
			tomtomBox[questId] = nil
			print(string.format("|cff%02x%02x%02x%s|r: 웨이포인트 제거", color.r*255, color.g*255, color.b*255, (qtitle or "퀘스트")))
			return 1
		else
			tomtomBox[questId] = TomTom:AddZWaypoint(c, z, posX*100, posY*100, string.format("|cff%02x%02x%02x%s|r", color.r*255, color.g*255, color.b*255, (qtitle or "퀘스트")), false)
			print(string.format("|cff%02x%02x%02x%s|r: 웨이포인트 추가", color.r*255, color.g*255, color.b*255, (qtitle or "퀘스트")))
			return 0
		end
	end
	return 0
end

function bqh_GetLeaderboardColor(text)
	local _,_,curcol,maxcol = string.find(text,".+: (%d+)/(%d+)")
	local color = {}

	if not curcol or not maxcol then
		_,_,curcol,maxcol = string.find(text, "(%d+)/(%d+)%s.+")
	end

	if( curcol and maxcol )then
		if curcol == maxcol then
			return {r=0.8, g=0.8, b=0.8}
		end

		local p = curcol / maxcol
		if p > 1 then
			color.r = 0.1
			color.g = 0.8
		elseif p < 0 then
			color.r = 0.8
			color.g = 0.1
		elseif p > .5 then
			color.r = 2.1-p*2
			color.g = 0.8
		else
			color.r = 0.8
			color.g = p*2
		end
		color.b = 0.1
		return color
	end
	return nil
end

function bqh_GetLeaderboardColor_Highlight(color)
	local c = {}
	c.r = color.r * 1.25
	c.g = color.g * 1.25
	c.b = color.b * 1.25
	return c
end


function bqh_GetQuestDifficultyColorByGradation(level)
	local color
	local plevel = UnitLevel("player") -- meh, should probably cache this, buuuuut
	local grayd

	if plevel >= 60 then
		grayd = 9
	elseif plevel >= 40 then
		grayd = plevel / 5 + 1
	else
		grayd = plevel / 10 + 5
	end

	if (plevel - floor(grayd) >= level) then
		color = {r=0.69, g=0.69, b=0.69}
	else
		color = difficulty_color(1 - ((level - plevel) / grayd + 1) / 2)
	end
	return color
end

local bqh_QuestDifficultyColors = {
	["impossible"]		= { r = 1.00, g = 0.10, b = 0.10 };
	["verydifficult"]	= { r = 1.00, g = 0.50, b = 0.25 };
	["difficult"]		= { r = 0.75, g = 0.61, b = 0.00 };
	["standard"]		= { r = 0.25, g = 0.75, b = 0.25 };
	["trivial"]			= { r = 0.50, g = 0.50, b = 0.50 };
	["header"]			= { r = 0.70, g = 0.70, b = 0.70 };
};
function bqh_GetQuestDifficultyColorByStep(level)
	local levelDiff = level - UnitLevel("player");
	local color;
	if ( levelDiff >= 5 ) then
		return bqh_QuestDifficultyColors["impossible"];
	elseif ( levelDiff >= 3 ) then
		return bqh_QuestDifficultyColors["verydifficult"];
	elseif ( levelDiff >= -2 ) then
		return bqh_QuestDifficultyColors["difficult"];
	elseif ( -levelDiff <= GetQuestGreenRange() ) then
		return bqh_QuestDifficultyColors["standard"];
	else
		return bqh_QuestDifficultyColors["trivial"];
	end
end

function bqh_GetQuestDifficultyColor(level)
	if BQH_CONFIG.QuestWatchColorType == 1 then
		return bqh_GetQuestDifficultyColorByStep(level)
	else
		return bqh_GetQuestDifficultyColorByGradation(level)
	end
end
function bqh_WatchFrameLinkButtonTemplate_Highlight(self, onEnter)
	local line;
	for index = self.startLine, self.lastLine do
		line = self.lines[index];
		if self.type == "QUEST" and BQH_CONFIG.QuestWatch == 1 then
			if ( line ) then
				local color
				if ( index == self.startLine ) then
					-- header
					if line.isDaily then
						color = {r=0.3, g=0.5, b=0.9}
					else
						color = bqh_GetQuestDifficultyColor(line.level) -- or UnitLevel("player"))
					end
					if ( onEnter ) then
						color = bqh_GetLeaderboardColor_Highlight(color)
					end
					line.text:SetTextColor(color.r, color.g, color.b);
				else
					color = bqh_GetLeaderboardColor(line.text:GetText())
					if color then
						if ( onEnter ) then
							if (line.text.eligible) then
								color = bqh_GetLeaderboardColor_Highlight(color)
							else
								color = RED_FONT_COLOR
							end
						else
							if (line.text.eligible) then
								--
							else
								color = DIM_RED_FONT_COLOR
							end
						end
						line.text:SetTextColor(color.r, color.g, color.b);
						line.dash:SetTextColor(color.r, color.g, color.b);
					else
						if ( onEnter ) then
							if (line.text.eligible) then
								line.text:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
							else
								line.text:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
							end
							line.dash:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
						else
							if (line.text.eligible) then
								line.text:SetTextColor(0.8, 0.8, 0.8);
							else
								line.text:SetTextColor(DIM_RED_FONT_COLOR.r, DIM_RED_FONT_COLOR.g, DIM_RED_FONT_COLOR.b);
							end
							line.dash:SetTextColor(0.8, 0.8, 0.8);
						end
					end
				end
			end
		else
			if ( line ) then
				if ( index == self.startLine ) then
					-- header
					if ( onEnter ) then
						line.text:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
					else
						line.text:SetTextColor(0.75, 0.61, 0);
					end
				else
					if ( onEnter ) then
						if (line.text.eligible) then
							line.text:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
						else
							line.text:SetTextColor(RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b);
						end
						line.dash:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
					else
						if (line.text.eligible) then
							line.text:SetTextColor(0.8, 0.8, 0.8);
						else
							line.text:SetTextColor(DIM_RED_FONT_COLOR.r, DIM_RED_FONT_COLOR.g, DIM_RED_FONT_COLOR.b);
						end
						line.dash:SetTextColor(0.8, 0.8, 0.8);
					end
				end
			end
		end
	end
end

function bqh_WatchFrame_SetLine(line, anchor, verticalOffset, isHeader, text, dash, hasItem, isComplete, eligible, level, isDaily)
	-- anchor
	if ( anchor ) then
		line:SetPoint("RIGHT", anchor, "RIGHT", 0, 0);
		line:SetPoint("LEFT", anchor, "LEFT", 0, 0);
		line:SetPoint("TOP", anchor, "BOTTOM", 0, verticalOffset);
	end
	line.level = level
	line.isDaily = isDaily

	-- text
	line.text:SetText(text);
	if ( isHeader ) then -- 퀘스트 제목
		BQH_WATCHFRAME_SETLINES_NUMLINES = 0;
		if ( BQH_CONFIG.QuestWatch == 1 ) then
			if isDaily then
				line.text:SetTextColor(0.3, 0.5, 0.9)
			else
				local qtc = bqh_GetQuestDifficultyColor(level)
				line.text:SetTextColor(qtc.r, qtc.g, qtc.b)
			end
		else
			line.text:SetTextColor(0.75, 0.61, 0)
		end
	else
		if not isComplete then -- 완료되지 않은 퀘스트 오브젝트들은 색상을 셋팅해준다.
			local qlc = bqh_GetLeaderboardColor(text)
			--text = WatchFrame_ReverseQuestObjective(text)
			if( qlc and BQH_CONFIG.QuestWatch == 1 )then
				if ( dash == DASH_SHOW ) then
					line.dash:SetTextColor(qlc.r, qlc.g, qlc.b)
				end
				line.text:SetTextColor(qlc.r, qlc.g, qlc.b)
			else
				if ( dash == DASH_SHOW ) then
					line.dash:SetTextColor(0.8, 0.8, 0.8)
				end
				line.text:SetTextColor(0.8, 0.8, 0.8)
			end
		else
			if ( dash == DASH_SHOW ) then
				line.dash:SetTextColor(0.8, 0.8, 0.8)
			end
		end
		--this should be the default, set in WatchFrameLineTemplate_Reset
		if ( eligible ~= nil and eligible == false) then
			line.text.eligible = eligible;
			--line.text:SetTextColor(DIM_RED_FONT_COLOR.r, DIM_RED_FONT_COLOR.g, DIM_RED_FONT_COLOR.b);
		else
			line.text.eligible = true;
			--line.text:SetTextColor(0.8, 0.8, 0.8);
		end
	end
	-- dash
	local usedWidth = 0;
	if ( dash == DASH_SHOW ) then
		line.dash:SetText(QUEST_DASH);
		usedWidth = DASH_WIDTH or 10;
	elseif ( dash == DASH_HIDE ) then
		line.dash:SetText(QUEST_DASH);
		line.dash:Hide();
		usedWidth = DASH_WIDTH or 10;
	elseif ( dash == DASH_ICON ) then
		line.dash:SetWidth(DASH_ICON_WIDTH);
		usedWidth = DASH_ICON_WIDTH or 20;
	end
	-- multiple lines
	if ( hasItem and BQH_WATCHFRAME_SETLINES_NUMLINES < 2 ) then
		usedWidth = usedWidth + WATCHFRAME_ITEM_WIDTH;
	end
	line.text:SetWidth(WATCHFRAME_MAXLINEWIDTH - usedWidth);
	if ( line.text:GetHeight() > WATCHFRAME_LINEHEIGHT ) then
		if ( isComplete ) then
			line:SetHeight(line.text:GetHeight() + 4);
		else
			line:SetHeight(WATCHFRAME_MULTIPLE_LINEHEIGHT);
			line.text:SetHeight(WATCHFRAME_MULTIPLE_LINEHEIGHT);
		end
		BQH_WATCHFRAME_SETLINES_NUMLINES = BQH_WATCHFRAME_SETLINES_NUMLINES + 2;
	else
		BQH_WATCHFRAME_SETLINES_NUMLINES = BQH_WATCHFRAME_SETLINES_NUMLINES + 1;
	end
	tinsert(BQH_WATCHFRAME_SETLINES, line);
end

function bqh_WatchFrameQuestPOI_OnClick(self, button)
	if button == "LeftButton" then
		QuestPOI_SelectButtonByQuestId("WatchFrameLines", self.questId, true);
		if ( WorldMapFrame:IsShown() ) then
			WorldMapFrame_SelectQuestById(self.questId);
		end
		SetSuperTrackedQuestID(self.questId);
		PlaySound("igMainMenuOptionCheckBoxOn");
	elseif button == "RightButton" then
		bhq_ToggleWayPoint(self.questId)
	end
end

function bqh_WorldMapQuestPOI_OnClick(self, button)
	if button == "LeftButton" then
		PlaySound("igMainMenuOptionCheckBoxOn");
		if ( self.quest ~= WORLDMAP_SETTINGS.selectedQuest ) then
			if ( WORLDMAP_SETTINGS.selectedQuest ) then
				WorldMapBlobFrame:DrawBlob(WORLDMAP_SETTINGS.selectedQuestId, false);
			end
			WorldMapFrame_SelectQuestFrame(self.quest);
		end
		if ( IsShiftKeyDown() ) then
			local isChecked = not WorldMapTrackQuest:GetChecked();
			WorldMapTrackQuest:SetChecked(isChecked);		
			WorldMapTrackQuest_Toggle(isChecked);
		end
	elseif button == "RightButton" then
		bhq_ToggleWayPoint(self.questId)
	end
end

function bhq_DisplayTrackedQuests(lineFrame, nextAnchor, maxHeight, frameWidth)
	local _;
	local questTitle;
	local questIndex;
	local line;
	local lastLine;
	local linkButton;
	local watchItemIndex = 0;
	local numVisible = 0;

	local numPOINumeric = 0;
	local numPOICompleteIn = 0;
	local numPOICompleteOut = 0;

	local text, finished, objectiveType;
	local numQuestWatches = GetNumQuestWatches();
	local numObjectives;
	local title, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID;
	local numValidQuests = 0;

	local maxWidth = 0;
	local lineWidth = 0;
	local topEdge = 0;

	local playerMoney = GetMoney();
	if ( not WorldMapFrame or not WorldMapFrame:IsShown() ) then
		-- For the filter REMOTE ZONES: when it's unchecked we need to display local POIs only. Unfortunately all the POI
		-- code uses the current map so the tracker would not display the right quests if the world map was windowed and
		-- open to a different zone.
		table.wipe(LOCAL_MAP_QUESTS);
		LOCAL_MAP_QUESTS["zone"] = GetCurrentMapZone();
		for id in pairs(CURRENT_MAP_QUESTS) do
			LOCAL_MAP_QUESTS[id] = true;
		end	
	end

	table.wipe(VISIBLE_WATCHES);
	bqh_ResetQuestLines()

	-- if supertracked quest is not in the quest log anymore, stop supertracking it
	if ( GetQuestLogIndexByID(GetSuperTrackedQuestID()) == 0 ) then
		SetSuperTrackedQuestID(0);
	end

	local inScenario = C_Scenario.IsInScenario();

	for i = 1, numQuestWatches do
		local validQuest = false;
		BQH_WATCHFRAME_SETLINES = table.wipe(BQH_WATCHFRAME_SETLINES or { });
		questIndex = GetQuestIndexForWatch(i);
		if ( questIndex ) then
			-- don't show non-scenario quests in scenarios
			if ( not inScenario or GetQuestLogQuestType(questIndex) == QUEST_TYPE_SCENARIO ) then
				validQuest = true;
			end
		end
		if ( validQuest ) then
			numValidQuests = numValidQuests + 1;
			title, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID, startEvent = GetQuestLogTitle(questIndex)
			
			if (GetSuperTrackedQuestID() == 0) then
				SetSuperTrackedQuestID(questID);
			end

			local questFailed = false;
			local requiredMoney = GetQuestLogRequiredMoney(questIndex);
			numObjectives = GetNumQuestLeaderBoards(questIndex);
			if ( isComplete and isComplete < 0 ) then
				isComplete = false;
				questFailed = true;
			elseif ( numObjectives == 0 and playerMoney >= requiredMoney and not startEvent ) then
				isComplete = true;
			end
			-- check filters
			local filterOK = true;
			if ( isComplete and bit.band(WATCHFRAME_FILTER_TYPE, WATCHFRAME_FILTER_COMPLETED_QUESTS) ~= WATCHFRAME_FILTER_COMPLETED_QUESTS ) then
				filterOK = false;
			elseif ( bit.band(WATCHFRAME_FILTER_TYPE, WATCHFRAME_FILTER_REMOTE_ZONES) ~= WATCHFRAME_FILTER_REMOTE_ZONES and not LOCAL_MAP_QUESTS[questID] ) then
				filterOK = false;
			end

			if ( filterOK ) then
				local link, item, charges, showItemWhenComplete = GetQuestLogSpecialItemInfo(questIndex);
				if ( requiredMoney > 0 ) then
					WatchFrame.watchMoney = true;	-- for update event
				end
				questTitle = bqh_GetQuestLine();
				bqh_WatchFrame_SetLine(questTitle, lastLine, -WATCHFRAME_QUEST_OFFSET, IS_HEADER, title, DASH_NONE, item, nil, nil, level, isDaily);
				if ( not lastLine ) then -- First line
					questTitle:SetPoint("RIGHT", lineFrame, "RIGHT", 0, 0);
					questTitle:SetPoint("LEFT", lineFrame, "LEFT", 0, 0);
					if (nextAnchor) then
						questTitle:SetPoint("TOP", nextAnchor, "BOTTOM", 0, -WATCHFRAME_TYPE_OFFSET);
					else
						questTitle:SetPoint("TOP", lineFrame, "TOP", 0, -WATCHFRAME_INITIAL_OFFSET);
					end
					topEdge = questTitle:GetTop();
				end
				lastLine = questTitle;

				if ( isComplete ) then
					local showItem = item and showItemWhenComplete;
					if (GetQuestLogIsAutoComplete(questIndex)) then
						line = bqh_GetQuestLine(); line.level = level; line.isDaily = isDaily;
						bqh_WatchFrame_SetLine(line, lastLine, WATCHFRAMELINES_FONTSPACING, not IS_HEADER, QUEST_WATCH_QUEST_COMPLETE, DASH_HIDE, showItem, true, nil, level, isDaily);
						lastLine = line;
						line = bqh_GetQuestLine();
						bqh_WatchFrame_SetLine(line, lastLine, WATCHFRAMELINES_FONTSPACING, not IS_HEADER, QUEST_WATCH_CLICK_TO_COMPLETE, DASH_HIDE, showItem, true, nil, level, isDaily); -- 이거 level, isDaily맞는건지 확인해볼것
						lastLine = line;
					else
						line = bqh_GetQuestLine(); line.level = level; line.isDaily = isDaily;
						bqh_WatchFrame_SetLine(line, lastLine, WATCHFRAMELINES_FONTSPACING, not IS_HEADER, GetQuestLogCompletionText(questIndex), DASH_SHOW, showItem, true, nil, level, isDaily);
						lastLine = line;
					end
				elseif ( questFailed ) then
					line = bqh_GetQuestLine(); line.level = level; line.isDaily = isDaily;
					bqh_WatchFrame_SetLine(line, lastLine, WATCHFRAMELINES_FONTSPACING, not IS_HEADER, FAILED, DASH_HIDE, nil, nil, false, level, isDaily);
					lastLine = line;
				else
					for j = 1, numObjectives do
						text, objectiveType, finished = GetQuestLogLeaderBoard(j, questIndex);
						if ( not finished and text ) then
							-- 아래 라인 주석풀면 "- 0/10 내용"으로 바뀜
							text = ReverseQuestObjective(text, objectiveType);
							line = bqh_GetQuestLine();
							line.level = level
							line.isDaily = isDaily
							bqh_WatchFrame_SetLine(line, lastLine, WATCHFRAMELINES_FONTSPACING, not IS_HEADER, text, DASH_SHOW, item, nil, nil, level, isDaily);
							lastLine = line;
						end
					end
					if ( requiredMoney > playerMoney ) then
						text = GetMoneyString(playerMoney).." / "..GetMoneyString(requiredMoney);
						line = bqh_GetQuestLine();
						line.level = level
						line.isDaily = isDaily
						bqh_WatchFrame_SetLine(line, lastLine, WATCHFRAMELINES_FONTSPACING, not IS_HEADER, text, DASH_SHOW, item, nil, nil, level, isDaily);
						lastLine = line;
					end
				end

				-- stop processing if there's no room to fit the quest
				local numLines = #BQH_WATCHFRAME_SETLINES;
				local lastBottom = lastLine:GetBottom();
				if ( lastBottom and lastBottom < WatchFrame:GetBottom() ) then
					questLineIndex = questLineIndex - numLines;
					table.wipe(BQH_WATCHFRAME_SETLINES);
					break;
				end

				numVisible = numVisible + 1;
				table.insert(VISIBLE_WATCHES, numVisible, questIndex);		-- save the quest log index because watch order can change after dropdown is opened
				-- turn on quest item
				local itemButton;
				if ( item and (not isComplete or showItemWhenComplete) ) then
					watchItemIndex = watchItemIndex + 1;
					itemButton = _G["WatchFrameItem"..watchItemIndex];
					if ( not itemButton ) then
						WATCHFRAME_NUM_ITEMS = watchItemIndex;
						itemButton = CreateFrame("BUTTON", "WatchFrameItem" .. watchItemIndex, lineFrame, "WatchFrameItemButtonTemplate");
					end
					itemButton:Show();
					itemButton:ClearAllPoints();
					itemButton:SetID(questIndex);
					SetItemButtonTexture(itemButton, item);
					SetItemButtonCount(itemButton, charges);
					itemButton.charges = charges;
					WatchFrameItem_UpdateCooldown(itemButton);
					itemButton.rangeTimer = -1;
					itemButton:SetPoint("TOPRIGHT", questTitle, "TOPRIGHT", 10, -2);
				end
				-- turn on all lines
				for _, line in pairs(BQH_WATCHFRAME_SETLINES) do
					line:Show();
					lineWidth = line.text:GetWidth() + line.dash:GetWidth();
					maxWidth = max(maxWidth, lineWidth);
				end
				-- turn on link button
				linkButton = bqh_GetLinkButton();
				linkButton:SetPoint("TOPLEFT", questTitle);
				linkButton:SetPoint("BOTTOMLEFT", questTitle);
				linkButton:SetPoint("RIGHT", questTitle.text);
				linkButton.type = "QUEST"
				linkButton.index = i; -- We want the Watch index, we'll get the quest index later with GetQuestIndexForWatch(i);
				linkButton.lines = WATCHFRAME_QUESTLINES;
				linkButton.startLine = questLineIndex - numLines;
				linkButton.lastLine = questLineIndex - 1;
				linkButton.isComplete = isComplete;
				linkButton:Show();
				-- quest POI icon
				if ( WatchFrame.showObjectives ) then
					local poiButton;
					if ( CURRENT_MAP_QUESTS[questID] ) then
						if ( isComplete ) then
							numPOICompleteIn = numPOICompleteIn + 1;
							poiButton = QuestPOI_DisplayButton("WatchFrameLines", QUEST_POI_COMPLETE_IN, numPOICompleteIn, questID);
						else
							numPOINumeric = numPOINumeric + 1;
							poiButton = QuestPOI_DisplayButton("WatchFrameLines", QUEST_POI_NUMERIC, numPOINumeric, questID);
						end
					elseif ( isComplete ) then
						numPOICompleteOut = numPOICompleteOut + 1;
						poiButton = QuestPOI_DisplayButton("WatchFrameLines", QUEST_POI_COMPLETE_OUT, numPOICompleteOut, questID);
					end
					if ( poiButton ) then
						poiButton:SetPoint("TOPRIGHT", questTitle, "TOPLEFT", 0, 5);
						poiButton.questLogIndex = CURRENT_MAP_QUESTS[questID];
					end
				end
			end
		end
	end

	for i = watchItemIndex + 1, WATCHFRAME_NUM_ITEMS do
		_G["WatchFrameItem" .. i]:Hide();
	end
	QuestPOI_HideButtons("WatchFrameLines", QUEST_POI_NUMERIC, numPOINumeric + 1);
	QuestPOI_HideButtons("WatchFrameLines", QUEST_POI_COMPLETE_IN, numPOICompleteIn + 1);
	QuestPOI_HideButtons("WatchFrameLines", QUEST_POI_COMPLETE_OUT, numPOICompleteOut + 1);

	bqh_ReleaseUnusedQuestLines()

	local trackedQuestID = GetSuperTrackedQuestID();
	if ( trackedQuestID ) then
		QuestPOIUpdateIcons();
		QuestPOI_SelectButtonByQuestId("WatchFrameLines", trackedQuestID, true);
	end

	return lastLine or nextAnchor, maxWidth, numValidQuests, 0;
end

function bqh_WatchFrame_Update (self)
	self = self or WatchFrame; -- Speeds things up if we pass in this reference when we can conveniently.
	-- Display things in this order: quest timers, achievements, quests, addon subscriptions.
	if ( self.updating ) then
		return;
	end

	self.updating = true;
	self.watchMoney = false;

	local nextAnchor = nil;
	local lineFrame = WatchFrameLines;
	local maxHeight = (WatchFrame:GetTop() - WatchFrame:GetBottom()); -- Can't use lineFrame:GetHeight() because it could be an invalid rectangle (width of 0)

	local maxFrameWidth = WATCHFRAME_MAXLINEWIDTH;
	local maxWidth = 0;
	local maxLineWidth, numObjectives;
	local totalObjectives = 0;
	--WATCHFRAME_NUM_POPUPS = 0;

	local wfa_index = 1
	while _G["WatchFrameAutoQuestPopUp"..wfa_index] do
		if _G["WatchFrameAutoQuestPopUp"..wfa_index] and _G["WatchFrameAutoQuestPopUp"..wfa_index]:IsShown() then
			nextAnchor = _G["WatchFrameAutoQuestPopUp"..wfa_index]
		end
		wfa_index = wfa_index + 1
	end
	for i = 1, #WATCHFRAME_TIMERLINES do
		line = WATCHFRAME_TIMERLINES[i];
		if line and line:IsShown() then
			nextAnchor = line
		end
	end
	for i = 1, #WATCHFRAME_ACHIEVEMENTLINES do
		line = WATCHFRAME_ACHIEVEMENTLINES[i];
		if line and line:IsShown() then
			nextAnchor = line
		end
	end

	bqh_ResetLinkButtons();

	nextAnchor, maxLineWidth, numObjectives, numPopUps = bhq_DisplayTrackedQuests(lineFrame, nextAnchor, maxHeight, maxFrameWidth)
	maxWidth = max(maxLineWidth, maxWidth);
	totalObjectives = totalObjectives + numObjectives

	if ( totalObjectives > 0 ) then
		WatchFrameHeader:Show();
		WatchFrameCollapseExpandButton:Show();
		WatchFrameTitle:SetText(OBJECTIVES_TRACKER_LABEL.." ("..totalObjectives..")");
		WatchFrameHeader:SetWidth(WatchFrameTitle:GetWidth() + 4);
		-- visible objectives?
		if ( nextAnchor ) then
			if ( self.collapsed and not self.userCollapsed ) then
				WatchFrame_Expand(self);
			end
			WatchFrameCollapseExpandButton:Enable();
		else
			if ( not self.collapsed ) then
				WatchFrame_Collapse(self);
			end
			WatchFrameCollapseExpandButton:Disable();
		end
	else
		WatchFrameHeader:Hide();
		WatchFrameCollapseExpandButton:Hide();
	end

	bqh_ReleaseUnusedLinkButtons();

	self.updating = nil;
	self.nextAnchor = nextAnchor;

	-- 제외된 퀘스트중 tomtom에 있던거는 뺀다;
	local title, color, level, questIndex, questLogIndex
	local numQuestWatches = GetNumQuestWatches()
	local ta = {}
	for qid, ttuid in pairs(tomtomBox) do
		questLogIndex = getQuestLogIndexByQuestId(qid)
		if questLogIndex then
			ta[questLogIndex] = qid
		end
	end
	for i=1, numQuestWatches, 1 do
		questIndex = GetQuestIndexForWatch(i)
		if questIndex then
			ta[questIndex] = nil
		end
	end
	for k, v in pairs(ta) do
		title, level = GetQuestLogTitle(k)
		color = bqh_GetQuestDifficultyColor(level)
		TomTom:RemoveWaypoint(tomtomBox[v])
		if tomtomBox[v] then
			tomtomBox[v] = nil
			print(string.format("|cff%02x%02x%02x%s|r: 웨이포인트 제거", color.r*255, color.g*255, color.b*255, (title or "퀘스트")))
		end
	end
end


function BlinkQuestHelper_Init()
	if not BQH_CONFIG then
		BQH_CONFIG = {}
	end
	if not BQH_CONFIG.QuestLevel then
		BQH_CONFIG.QuestLevel = 1
	end
	if not BQH_CONFIG.QuestWatch then
		BQH_CONFIG.QuestWatch = 1
	end
	if not BQH_CONFIG.QuestAutoAdd then
		BQH_CONFIG.QuestAutoAdd = 1
		setglobal("AUTO_QUEST_WATCH","1")
	end
	if not BQH_CONFIG.QuestAutoRemove then
		BQH_CONFIG.QuestAutoRemove = 1
	end
	if not BQH_CONFIG.QuestAnnounceToParty then
		BQH_CONFIG.QuestAnnounceToParty = 1
	end
	if not BQH_CONFIG.QuestCompleteSound then
		BQH_CONFIG.QuestCompleteSound = 0
	end
	if not BQH_CONFIG.QuestCompleteSoundFile then
		BQH_CONFIG.QuestCompleteSoundFile = "PVPENTERQUEUE"
	end
	if not BQH_CONFIG.QuestUpdateSoundFile then
		BQH_CONFIG.QuestUpdateSoundFile = "Sound/Spells/Bonk1.ogg"
	end
	if ( BQH_CONFIG.QuestAutoAdd == 1 ) then
		setglobal("AUTO_QUEST_WATCH","1")
	end
	if not BQH_CONFIG.QuestWatchColorType then
		BQH_CONFIG.QuestWatchColorType = 1
	end

	-- hack
	_G.WATCHFRAME_MAXLINEWIDTH = 202
	_G.WATCHFRAME_QUEST_OFFSET = 0

	-- hooks
	hooksecurefunc("WatchFrame_Update", bqh_WatchFrame_Update)

	QuestLogTitleButton_OnClick = bqh_QuestLogTitleButton_OnClick
	WatchFrameLinkButtonTemplate_Highlight = bqh_WatchFrameLinkButtonTemplate_Highlight
	ori_GetQuestLogTitle = GetQuestLogTitle
	GetQuestLogTitle = bqh_GetQuestLogTitle

	if QuestPOI_DisplayButton and TomTom then
		hooksecurefunc("QuestPOI_DisplayButton", function (parentName, buttonType, buttonIndex, questId)
			local buttonName = "poi"..parentName..buttonType.."_"..buttonIndex
			local poiButton = _G[buttonName]

			if poiButton then
				poiButton:RegisterForClicks("LeftButtonUp", "RightButtonUp")
				if buttonType == QUEST_POI_COMPLETE_SWAP and QUEST_POI_SWAP_BUTTONS[parentName] then
					QUEST_POI_SWAP_BUTTONS[parentName].questId = questId
					QUEST_POI_SWAP_BUTTONS[parentName]:RegisterForClicks("LeftButtonUp", "RightButtonUp")
				end
			end
			return poiButton
		end)
		WatchFrameQuestPOI_OnClick = bqh_WatchFrameQuestPOI_OnClick
		WorldMapQuestPOI_OnClick = bqh_WorldMapQuestPOI_OnClick
	end
end

function BlinkQuestHelper_ToggleQuestLevel(toggle)
	if( toggle == 1 )then
		BQH_CONFIG.QuestLevel = 1
	elseif( toggle == 0 )then
		BQH_CONFIG.QuestLevel = 0
	else
		if( BQH_CONFIG.QuestLevel ~= 1 )then
			BQH_CONFIG.QuestLevel = 1
		else
			BQH_CONFIG.QuestLevel = 0
		end
	end
	QuestLog_Update()
	WatchFrame_Update()
end

function BlinkQuestHelper_ToggleQuestWatch(toggle)
	if( toggle == 1 )then
		BQH_CONFIG.QuestWatch = 1
	elseif( toggle == 0 )then
		BQH_CONFIG.QuestWatch = 0
	else
		if( BQH_CONFIG.QuestWatch ~= 1 )then
			BQH_CONFIG.QuestWatch = 1
		else
			BQH_CONFIG.QuestWatch = 0
		end
	end
	QuestLog_Update()
	WatchFrame_Update()
end

function BlinkQuestHelper_ToggleQuestWatchColorType(toggle)
	if( toggle == 1 )then
		BQH_CONFIG.QuestWatchColorType = 1
	elseif( toggle == 0 )then
		BQH_CONFIG.QuestWatchColorType = 0
	else
		if( BQH_CONFIG.QuestWatchColorType ~= 1 )then
			BQH_CONFIG.QuestWatchColorType = 1
		else
			BQH_CONFIG.QuestWatchColorType = 0
		end
	end
	QuestLog_Update()
	WatchFrame_Update()
end

function BlinkQuestHelper_SlashCmd(msg)
	local cmd = gsub(msg, "%s*([^%s]+).*", "%1")

	if( strlen(cmd) <= 0 ) then
		BlinkQuestHelper_Usage()
		return
	end

	if( cmd == "레벨" )then
		BlinkQuestHelper_ToggleQuestLevel()
		if( BQH_CONFIG.QuestLevel == 1 )then
			print("퀘스트목록에 레벨을 표시합니다.")
		else
			print("퀘스트목록에 레벨을 표시하지 않습니다.")
		end
		return
	elseif( cmd == "색상" )then
		BlinkQuestHelper_ToggleQuestWatch()
		if( BQH_CONFIG.QuestWatch == 1 )then
			print("퀘스트도우미의 진행상황을 색상으로 표시해줍니다.")
		else
			print("퀘스트도우미를 원래 기능으로 되돌립니다.")
		end
		return
	elseif( cmd == "색상타입" )then
		if BQH_CONFIG.QuestWatch == 1 then
			BlinkQuestHelper_ToggleQuestWatchColorType()
			if( BQH_CONFIG.QuestWatchColorType == 1 )then
				print("퀘스트도우미의 진행상황을 색상을 난이도별로 표시합니다.")
				print(" - |cff7f7f7f회색|r: 저레벨")
				print(" - |cff3fbf3f녹색|r: 보통")
				print(" - |cffbf9b00노란색|r: 어려움")
				print(" - |cffff7f3f주황색|r: 매우 어려움")
				print(" - |cffff1919빨간색|r: 불가능")
			else
				print("퀘스트도우미의 진행상황을 색상을 자연스럽게 표시합니다.")
			end
		else
			print("퀘스트도우미의 진행상황을 색상으로 표시기능을 먼저 활성화하십시오.")
		end
		return
	elseif( cmd == "자동제거" )then
		if( BQH_CONFIG.QuestAutoRemove == 0 )then
			print("퀘스트도우미에 등록된 퀘스트중 완료된 퀘스트는 자동으로 제거합니다.")
			BQH_CONFIG.QuestAutoRemove = 1
		else
			print("퀘스트가 완료되도 퀘스트도우미 리스트에서 자동으로 제거하지 않습니다.")
			BQH_CONFIG.QuestAutoRemove = 0
		end
		return
	elseif( cmd == "자동추가" )then
		if( BQH_CONFIG.QuestAutoAdd == 0 )then
			print("퀘스트아이템을 얻으면 퀘스트도우미에 자동으로 추가합니다.")
			BQH_CONFIG.QuestAutoAdd = 1
			setglobal("AUTO_QUEST_WATCH","1")
		else
			print("퀘스트도우미에 수동으로 추가해야합니다.-_-")
			BQH_CONFIG.QuestAutoAdd = 0
			setglobal("AUTO_QUEST_WATCH","0")
		end
		return
	elseif( cmd == "파티알림" )then
		if( BQH_CONFIG.QuestAnnounceToParty == 0 )then
			print("퀘스트아이템을 얻으면 파티원에게 알려줍니다.")
			BQH_CONFIG.QuestAnnounceToParty = 1
		else
			print("파티원에게 알리지않습니다.")
			BQH_CONFIG.QuestAnnounceToParty = 0
		end
		return
	elseif( cmd == "설정보기" or cmd == "?" )then
		BlinkQuestHelper_Status()
		return
	end
	BlinkQuestHelper_Usage()
end

function BlinkQuestHelper_Usage()
	print("퀘스트도우미 사용방법:")
	print(" /퀘도우미          : 도움말")
	print(" /퀘도우미 레벨     : 퀘스트목록에서 레벨을 표시해줍니다.")
	print(" /퀘도우미 색상     : 퀘스트도우미의 진행상황을 색상으로 표시해줍니다.")
	print(" /퀘도우미 색상타입 : 퀘스트도우미의 진행상황 색상표시 방식을 전환합니다.")
	print(" /퀘도우미 자동추가 : 퀘스트도우미에 자동으로 추가")
	print(" /퀘도우미 자동제거 : 완료된 퀘스트 자동으로 제거")
	print(" /퀘도우미 파티알림 : 퀘스트 진행상황을 파티원에게 알립니다.")
	print(" /퀘도우미 설정보기 : 퀘스트도우미 설정상태를 확인할수 있습니다.")
end

function BlinkQuestHelper_Status()
	print("퀘스트도우미 설정상태:")
	if( BQH_CONFIG.QuestLevel == 1 )then
		print("  퀘스트레벨표시 : |cff00ff00켜짐|r")
	else
		print("  퀘스트레벨표시 : |cffff0000꺼짐|r")
	end
	if( BQH_CONFIG.QuestWatch == 1 )then
		print("  퀘스트도우미 색상표시 : |cff00ff00켜짐|r")
		if BQH_CONFIG.QuestWatchColorType == 1 then
			print("  퀘스트도우미 색상타입 : |cff00ff00단계적으로 변화|r")
		else
			print("  퀘스트도우미 색상타입 : |cff00ff00부드럽게 변화|r")
		end
	else
		print("  퀘스트도우미 색상표시 : |cffff0000꺼짐|r")
	end
	if( BQH_CONFIG.QuestAutoAdd == 1 )then
		print("  퀘스트도우미 자동추가 : |cff00ff00켜짐|r")
	else
		print("  퀘스트도우미 자동추가 : |cffff0000꺼짐|r")
	end
	if( BQH_CONFIG.QuestAutoRemove == 1 )then
		print("  퀘스트도우미 자동제거 : |cff00ff00켜짐|r")
	else
		print("  퀘스트도우미 자동제거 : |cffff0000꺼짐|r")
	end
	if( BQH_CONFIG.QuestAnnounceToParty == 1 )then
		print("  퀘스트도우미 파티알림 : |cff00ff00켜짐|r")
	else
		print("  퀘스트도우미 파티알림 : |cffff0000꺼짐|r")
	end
end

function BlinkQuestHelper_QuestCompleteCheck()
	for questIndex, _ in pairs(completeCheckBox) do
		local questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID, displayQuestID = GetQuestLogTitle(questIndex)
		if questID and questID>0 then
			if isComplete and isComplete > 0 then
				--local qlink = GetQuestLink(questIndex);
				--print(qlink .. " 퀘스트 완료["..questIndex.."]")
				if BQH_CONFIG.QuestCompleteSound == 1 then
					playSoundFor(BQH_CONFIG.QuestCompleteSoundFile)
				end
				completeCheckBox[questIndex] = nil
			else
				--local qlink = GetQuestLink(questIndex);
				--print(qlink .. " 퀘스트 업데이트["..questIndex.."]")
				if BQH_CONFIG.QuestCompleteSound == 1 then
					playSoundFor(BQH_CONFIG.QuestUpdateSoundFile)
				end
			end
		end
	end
end

function BlinkQuestHelper_QuestCompleteAnnounce(msg)
	local questIndex, pcs, goal = BlinkQuestHelper_FindQuestIndexByUIMessage(msg)
	if questIndex then
		if pcs and goal and pcs == goal then
			completeCheckBox[questIndex] = 1
		end
	end
end

function BlinkQuestHelper_QuestWatchAutoRemove()
	local needUpdate = false
	local numQuestWatches = GetNumQuestWatches()
	for i=1, numQuestWatches do
		questIndex = GetQuestIndexForWatch(i)
		if ( questIndex ) then
			local _, _, _, _, isHeader, _, isComplete = GetQuestLogTitle(questIndex)
			if ( not isHeader ) then
				if ( isComplete and isComplete > 0 ) then
					RemoveQuestWatch(questIndex)
					needUpdate = true
				end
			end
		end
	end
	if( needUpdate )then WatchFrame_Update() end
end

function BlinkQuestHelper_FindQuestIndexByUIMessage(message)
	local text, type_, finished
	for i=1, GetNumQuestLogEntries(), 1 do
		numObjectives = GetNumQuestLeaderBoards(i)
		if( numObjectives > 0 )then
			for j=1, numObjectives do
				text, type_, finished = GetQuestLogLeaderBoard(j, i)
				if text then
					local _, _, a, b = text:find(".+: (%d+)/(%d+)")
					if (gsub(message,"(.*): %d+/%d+","%1",1) == gsub(text,"(.*): %d+/%d+","%1",1)) then
						return i, a, b
					end
				end
			end
		end
	end
	return nil
end

function BQH_QuestAnnounceToParty(msg)
	local updatedIndex, pcs, goal = BlinkQuestHelper_FindQuestIndexByUIMessage(msg)
	if( updatedIndex )then
		local questLogTitleText, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID, displayQuestID = GetQuestLogTitle(updatedIndex)
		local title = GetQuestLink(updatedIndex)
		if title and BQH_CONFIG.QuestAnnounceToParty == 1 and GetNumSubgroupMembers()>0 then
			title = "Lv."..level..title .. " " .. msg
			SendChatMessage( title, "PARTY" )
		end
	end
end

function BlinkQuestHelper_Notice(questTitle, questIndex, chat, who)
	local questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID, displayQuestID = GetQuestLogTitle(questIndex)
	local questString = {}
	local title = GetQuestLink(questIndex)
	local numObjectives = GetNumQuestLeaderBoards(questIndex)
	local complete = ""

	if ( isComplete and isComplete < 0 ) then
		complete = " - ("..FAILED..")"
	elseif ( isComplete and isComplete > 0 ) then
		complete = " - ("..COMPLETE..")"
	end
	if ( isDaily ) then
		if ( questTag ) then
			questTag = format(DAILY_QUEST_TAG_TEMPLATE, questTag)
		else
			questTag = DAILY
		end
	end

	title = title .. complete

	table.insert(questString, title)
	for i=1, numObjectives, 1 do
		local text, type, finished = GetQuestLogLeaderBoard(i,questIndex)
		if ( not text or strlen(text) == 0 ) then
			text = type
		end
		if ( finished ) then
			text = text.." ("..COMPLETE..")"
		end
		text = "  - "..text
		table.insert(questString, text)
	end
	if ( table.getn(questString) > 1 ) then
		for i=1, table.getn(questString) do
			SendChatMessage(questString[i], chat, GetDefaultLanguage(), who)
		end
	end
end

function BlinkQuestHelper_ShowDropdown(questTitle,questIndex)
	HideDropDownMenu(1)
	if ( questIndex ) then
		UIDropDownMenu_Initialize(dropdown, function ()
			local info = {}
			info.isTitle = 1
			info.text = "진행상황 알림"
			UIDropDownMenu_AddButton(info)

			info = {}
			info.text = "일반 대화"
			info.func = function ()
				BlinkQuestHelper_Notice(questTitle,questIndex,"SAY")
			end
			UIDropDownMenu_AddButton(info)

			info = {}
			info.text = "외치기"
			info.func = function ()
				BlinkQuestHelper_Notice(questTitle,questIndex,"YELL")
			end
			UIDropDownMenu_AddButton(info)

			if ( GetNumSubgroupMembers() > 0 ) then
				info = {}
				info.text = "파티원"
				info.func = function ()
					BlinkQuestHelper_Notice(questTitle,questIndex,"PARTY")
				end
				UIDropDownMenu_AddButton(info)
			end
			if ( UnitInRaid("player") ) then
				info = {}
				info.text = "공대원"
				info.func = function ()
					BlinkQuestHelper_Notice(questTitle,questIndex,"RAID")
				end
				UIDropDownMenu_AddButton(info)
			end

			if ( UnitExists("target") and UnitIsFriend("player","target") and UnitIsPlayer("target") and not UnitIsUnit("player","target") ) then
				info = {}
				info.text = "귓속말 : "..UnitName("target")
				info.func = function ()
					BlinkQuestHelper_Notice(questTitle,questIndex,"WHISPER",UnitName("target"))
				end
				UIDropDownMenu_AddButton(info)
			end

			if ( IsInGuild() ) then
				info = {}
				info.text = "길드"
				info.func = function ()
					BlinkQuestHelper_Notice(questTitle,questIndex,"GUILD")
				end
				UIDropDownMenu_AddButton(info)
			end
		end ,"MENU")
		ToggleDropDownMenu(1, nil, dropdown, "cursor")
	end
end

function bqh_QuestLogTitleButton_OnClick(self, button)
	local questName = self:GetText()
	local questIndex = self:GetID()
	if ( button == "LeftButton" ) then
		if ( IsModifiedClick() ) then
			-- If header then return
			if ( self.isHeader ) then
				return
			end
			-- Otherwise try to track it or put it into chat
			if ( IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() ) then
				local questLink = GetQuestLink(questIndex);
				if ( questLink ) then
					ChatEdit_InsertLink(questLink);
				end
				QuestLog_SetSelection(questIndex);
				return
			elseif ( IsModifiedClick("QUESTWATCHTOGGLE") ) then
				_QuestLog_ToggleQuestWatch(questIndex);
				QuestLog_SetSelection(questIndex);
				QuestLog_Update();
			elseif IsModifiedClick("BQHANNOUNCEQUEST") then
				local questTitle, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID, displayQuestID = GetQuestLogTitle(questIndex)
				local questString = {}
				local title = GetQuestLink(questIndex)
				local numObjectives = GetNumQuestLeaderBoards(questIndex)
				local complete = ""

				if ( isComplete and isComplete < 0 ) then
					complete = " - ("..FAILED..")"
				elseif ( isComplete and isComplete > 0 ) then
					complete = " - ("..COMPLETE..")"
				end
				if ( isDaily ) then
					if ( questTag ) then
						questTag = format(DAILY_QUEST_TAG_TEMPLATE, questTag)
					else
						questTag = DAILY
					end
				end

				title = title .. complete

				table.insert(questString,title)
				for i=1, numObjectives, 1 do
					local text, type, finished = GetQuestLogLeaderBoard(i,questIndex)
					if ( not text or strlen(text) == 0 ) then
						text = type
					end
					if ( finished ) then
						text = text.." ("..COMPLETE..")"
					end
					text = "  - "..text
					table.insert(questString,text)
				end
				if ( table.getn(questString) > 1 ) then
					for i=1, table.getn(questString) do
						if ( GetNumSubgroupMembers()>0 and not UnitInRaid("player") ) then
							SendChatMessage(questString[i], "PARTY")
						elseif ( UnitInRaid("player") ) then
							SendChatMessage(questString[i], "RAID")
						else
							SendChatMessage(questString[i], "SAY")
						end
					end
				end
			end
		end
	else
		BlinkQuestHelper_ShowDropdown(self,questIndex)
	end

	QuestLog_SetSelection(questIndex)
	--QuestLog_Update()
end

--[[ 사용안함
function bqh_QuestLog_Update()
	if ( not QuestLogFrame:IsShown() ) then
		return;
	end

	local numEntries, numQuests = GetNumQuestLogEntries();
	if ( numEntries == 0 ) then
		HideUIPanel(QuestLogDetailFrame);
		QuestLogDetailFrame.timeLeft = nil;
		EmptyQuestLogFrame:Show();
		QuestLog_SetSelection(0);
	else
		EmptyQuestLogFrame:Hide();
	end

	QuestLog_UpdateMapButton();

	-- Update Quest Count
	QuestLog_UpdateQuestCount(numQuests);

	-- If no selection then set it to the first available quest
	local questLogSelection = GetQuestLogSelection();
	local haveSelection = questLogSelection ~= 0;
	if ( numQuests > 0 and not haveSelection ) then
		if ( QuestLogFrame.selectedIndex ) then
			QuestLog_SetNearestValidSelection();
		else
			QuestLog_SetFirstValidSelection();
		end
		questLogSelection = GetQuestLogSelection();
	end
	QuestLogFrame.selectedIndex = questLogSelection;

    --The counts may have changed with SetNearestValidSelection expanding quest headers.
    --Bug ID 170644
    numEntries, numQuests = GetNumQuestLogEntries();

	-- hide the details if we don't have a selected quest
	if ( not haveSelection ) then
		HideUIPanel(QuestLogDetailFrame);
	end

	-- update the group timer
	local haveGroup = GetNumSubgroupMembers() > 0 or GetNumGroupMembers() > 1;
	if ( haveGroup ) then
		QuestLogFrame.groupUpdateTimer = 0;
	else
		QuestLogFrame.groupUpdateTimer = nil;
	end

	-- hide the highlight frame initially, it may be shown when we loop through the quest listing if a quest is selected
	QuestLogHighlightFrame:Hide();

	-- Update the quest listing
	local buttons = QuestLogScrollFrame.buttons;
	local numButtons = #buttons;
	local scrollOffset = HybridScrollFrame_GetOffset(QuestLogScrollFrame);
	local buttonHeight = buttons[1]:GetHeight();
	local displayedHeight = 0;

	local numPartyMembers = GetNumSubgroupMembers();
	local questIndex, questLogTitle, questTitleTag, questNumGroupMates, questNormalText, questCheck;
	local title, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily;
	local color;
	local partyMembersOnQuest, tempWidth, textWidth;
	for i=1, numButtons do
		questLogTitle = buttons[i];
		questIndex = i + scrollOffset;
		questLogTitle:SetID(questIndex);
		questTitleTag = questLogTitle.tag;
		questNumGroupMates = questLogTitle.groupMates;
		questCheck = questLogTitle.check;
		questNormalText = questLogTitle.normalText;
		if ( questIndex <= numEntries ) then
			title, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID, displayQuestID = GetQuestLogTitle(questIndex);

			if ( isHeader ) then
				-- set the title
				if ( title ) then
					questLogTitle:SetText(title);
				else
					questLogTitle:SetText("");
				end

				-- set the normal texture based on the header's collapsed state
				if ( isCollapsed ) then
					questLogTitle:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
				else
					questLogTitle:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
				end
				questLogTitle:SetHighlightTexture("Interface\\Buttons\\UI-PlusButton-Hilight");

				questNumGroupMates:Hide();
				questTitleTag:Hide();
				questCheck:Hide();
			else
				-- set the title
				if (questID and displayQuestID) then
					questLogTitle:SetText("  "..questID.." - "..title);
				else
					questLogTitle:SetText("  "..title);
				end

				-- this isn't a header, hide the header textures
				questLogTitle:SetNormalTexture("");
				questLogTitle:SetHighlightTexture("");

				-- If not a header see if any nearby group mates are on this quest
				partyMembersOnQuest = 0;
				for j=1, numPartyMembers do
					if ( IsUnitOnQuest(questIndex, "party"..j) ) then
						partyMembersOnQuest = partyMembersOnQuest + 1;
					end
				end
				if ( partyMembersOnQuest > 0 ) then
					questNumGroupMates:SetText("["..partyMembersOnQuest.."]");
					questNumGroupMates:Show();
				else
					questNumGroupMates:Hide();
				end

				-- figure out which tag to show, if any
				if ( isComplete and isComplete < 0 ) then
					questTag = FAILED;
				elseif ( isComplete and isComplete > 0 ) then
					questTag = COMPLETE;
				elseif ( isDaily ) then
					if ( questTag ) then
						questTag = format(DAILY_QUEST_TAG_TEMPLATE, questTag);
					else
						questTag = DAILY;
					end
				end
				if ( questTag ) then
					questTitleTag:SetText("("..questTag..")");
					questTitleTag:Show();
				else
					questTitleTag:Hide();
				end

				-- show the quest check if the quest is being watched
				if ( IsQuestWatched(questIndex) ) then
					questCheck:Show();
				else
					questCheck:Hide();
				end
			end

			-- Save if its a header or not
			questLogTitle.isHeader = isHeader;

			-- resize the title button so everything fits where it's supposed to
			QuestLogTitleButton_Resize(questLogTitle);

			-- Color the quest title and highlight according to the difficulty level
			if ( isHeader ) then
				color = QuestDifficultyColors["header"];
			else
				color = GetQuestDifficultyColor(level);
			end
			questTitleTag:SetTextColor(color.r, color.g, color.b);
			questLogTitle:SetNormalFontObject(color.font);
			questNumGroupMates:SetTextColor(color.r, color.g, color.b);
			questLogTitle.r = color.r;
			questLogTitle.g = color.g;
			questLogTitle.b = color.b;
			questLogTitle:Show();

			-- Place the highlight and lock the highlight state
			if ( questLogSelection == questIndex ) then
				_QuestLog_HighlightQuest(questLogTitle);
			else
				questLogTitle:UnlockHighlight();
			end
		else
			questLogTitle:Hide();
		end
		displayedHeight = displayedHeight + buttonHeight;
	end
	HybridScrollFrame_Update(QuestLogScrollFrame, numEntries * buttonHeight, displayedHeight);

	-- update the control panel
	QuestLogControlPanel_UpdateState();
end
]]

-------------------------------------------------------------------------------
-- configure BlinkGUI
-------------------------------------------------------------------------------
function BQH_BlinkGUIRegister()
	if _G.BlinkConfig then
		_G.BlinkConfig:RegisterOptions{
			name = "퀘스트 도우미",
			type = "root",
			command = {"퀘도우미설정","qhelperconfig"},
			options = {
				{
					type = "description",
					text = "블링크의 퀘스트 도우미",
					fontobject = "QuestTitleFont",
					r = 1,
					g = 0.82,
					b = 0,
					justifyH = "LEFT",
				},
				{
					type = "description",
					text = "퀘스트 레벨표시, 자동으로 추가, 제거 기능 및 난이도별 색상 표시 기능, 파티원에게 퀘스트진행상황 알림 기능",
					fontobject = "ChatFontNormal",
					justifyH = "LEFT",
					justifyV = "TOP",
				},
				{
					type = "group",
					options = {
						{
							type = "toggle",
							text = "퀘스트 레벨 표시하기",
							tooltip = "퀘스트를 수행할수 있는 적정 레벨을 표시해줍니다.",
							get = function ()
								return BQH_CONFIG.QuestLevel == 1
							end,
							set = function (value)
								if value then
									BlinkQuestHelper_ToggleQuestLevel(1)
								else
									BlinkQuestHelper_ToggleQuestLevel(0)
								end
							end,
						},
						{
							type = "toggle",
							text = "퀘스트 자동으로 추가하기",
							tooltip = "퀘스트 아이템을 얻거나 적을 처치했을때, 자동으로 퀘스트알리미 목록에 추가합니다.",
							get = function ()
								return BQH_CONFIG.QuestAutoAdd == 1
							end,
							set = function (value)
								if value then
									BQH_CONFIG.QuestAutoAdd = 1
								else
									BQH_CONFIG.QuestAutoAdd = 0
								end
							end,
						},
						{
							type = "toggle",
							text = "완료된 퀘스트 자동으로 제거하기",
							tooltip = "퀘스트가 완료되었을때 자동으로 퀘스트알리미 목록에서 제거해줍니다.",
							get = function ()
								return BQH_CONFIG.QuestAutoRemove == 1
							end,
							set = function (value)
								if value then
									BQH_CONFIG.QuestAutoRemove = 1
								else
									BQH_CONFIG.QuestAutoRemove = 0
								end
							end,
						},
						{
							type = "toggle",
							text = "퀘스트 진행상황 파티원에게 알려주기",
							tooltip = "퀘스트의 진행상황을 파티원에게 알려줍니다.",
							get = function ()
								return BQH_CONFIG.QuestAnnounceToParty == 1
							end,
							set = function (value)
								if value then
									BQH_CONFIG.QuestAnnounceToParty = 1
								else
									BQH_CONFIG.QuestAnnounceToParty = 0
								end
							end,
						},
						{
							type = "toggle",
							text = "퀘스트 완료시 소리내기",
							tooltip = "퀘스트 완료시 소리로 알려줍니다.",
							get = function ()
								return BQH_CONFIG.QuestCompleteSound == 1
							end,
							set = function (value)
								if value then
									BQH_CONFIG.QuestCompleteSound = 1
								else
									BQH_CONFIG.QuestCompleteSound = 0
								end
							end,
							needRefresh = true,
						},
						{
							type = "group",
							options = {
								{
									type = "select",
									text = "퀘스트 업데이트 소리 선택",
									tooltip = "퀘스트 업데이트시 들려줄 소리를 선택합니다.",
									values = Complete_Sound,
									get = function()
										return BQH_CONFIG.QuestUpdateSoundFile
									end,
									set = function(value)
										BQH_CONFIG.QuestUpdateSoundFile = value
									end,
									--[[disable = function ()
										return BQH_CONFIG.QuestCompleteSound ~= 1
									end,]]
								},
								{
									type = "select",
									text = "퀘스트 완료 소리 선택",
									tooltip = "퀘스트 완료시 들려줄 소리를 선택합니다.",
									values = Complete_Sound,
									get = function()
										return BQH_CONFIG.QuestCompleteSoundFile
									end,
									set = function(value)
										BQH_CONFIG.QuestCompleteSoundFile = value
									end,
									--[[disable = function ()
										return BQH_CONFIG.QuestCompleteSound ~= 1
									end,]]
								},
							},
							disable = function ()
								return BQH_CONFIG.QuestCompleteSound~=1
							end,
						},
						{
							type = "toggle",
							text = "진행상황 색상 변화하기",
							tooltip = "퀘스트의 진행상황을 색상으로 표시해줍니다.",
							get = function ()
								return BQH_CONFIG.QuestWatch == 1
							end,
							set = function (value)
								if value then
									BlinkQuestHelper_ToggleQuestWatch(1)
								else
									BlinkQuestHelper_ToggleQuestWatch(0)
								end
							end,
							needRefresh = true,
						},
						{
							type = "radio",
							text = "진행상황 색상 변화 타입",
							values = {
								{text = "단계적으로 변화", value = 1},
								{text = "부드럽게 변화", value = 0},
							},

							get = function ()
								return BQH_CONFIG.QuestWatchColorType and BQH_CONFIG.QuestWatchColorType or 1
							end,
							set = function (value)
								BQH_CONFIG.QuestWatchColorType = value
								BlinkQuestHelper_ToggleQuestWatchColorType(value)
							end,
							col = 2,
							disable = function ()
								return BQH_CONFIG.QuestWatch ~= 1
							end,
						},
					},
				},
			},
		}
	end
end

function BlinkQuestHelper_OnEvent(self, event, ...)
	local arg1 = ...
	if event == "UPDATE_MOUSEOVER_UNIT" then
		setTootipQuestProgress(GameTooltip)
	elseif event == "QUEST_WATCH_UPDATE" then
		completeCheckBox[arg1] = 1
	elseif event == "UI_INFO_MESSAGE" then
		local questUpdateText = gsub(arg1, "(.*): %d+/%d+", "%1", 1)
		if ( questUpdateText ~= arg1 ) then
			BQH_QuestAnnounceToParty(arg1)
		end
	--elseif ( event == "QUEST_LOG_UPDATE" or event == "UPDATE_FACTION" or (event == "UNIT_QUEST_LOG_CHANGED" and arg1 == "player") ) then
	elseif event == "UNIT_QUEST_LOG_CHANGED" and arg1 == "player" then
		--[[if( BQH_CONFIG.QuestAutoRemove == 1 )then
			BlinkQuestHelper_QuestWatchAutoRemove()
		end]]
		--print(event)
		BlinkQuestHelper_QuestCompleteCheck()
	end
end

BlinkQuestHelperFrame = CreateFrame("Frame", "BlinkQuestHelperFrame")
BlinkQuestHelperFrame:RegisterEvent("ADDON_LOADED")
BlinkQuestHelperFrame:SetScript("OnEvent", function(this, event, ...)
	if event == "ADDON_LOADED" then
		load(this)
	end
end)

